
// 页面的数据源
let data = {
  couponDefineList: []
};

let status = {
  //新建或编辑的弹出框
  modalDistribute: {
    isShow: false
  }
};

let couponDefineTable = function(self){
  return [
    {
      type: 'selection',
      width: 55,
      fixed: 'left',
      align: 'center',
    },
    {
      type: 'index',
      width: 55,
      align: 'center',
      title: '#',
    },
    {
      title: '优惠券标题',
      key: 'title',
      width: 200,
      render:(h, params) => {
        if(self.$authority("COUPONS-1-204")){
          return (<div><a href="javascript:void(0);" onClick={() => {self.showCouponModelInfo(params.row.id);}}>{params.row.title}</a></div>);
        } else {
          return (<div>{params.row.title}</div>);
        }
      }
    },
    {
      title: '优惠券类型',
      key: 'type',
      width: 120,
      align: 'center',
      render: (h, params) => {
        let couponTypeDict = self.couponTypeDict;
        let type = params.row.type;
        let typeItem = couponTypeDict.filter(item=>item.value===type);
        let isPrimary = type===200;
        return (
          <div>
            <tag color={isPrimary?'green':'magenta'}>{isPrimary?'折扣券':'现金抵扣券'}</tag>
          </div>
        );
      },
    },
    {
      title: '启用状态',
      key: 'state',
      width: 110,
      render: (h, params) => {
        let isOpened = params.row.state === 0;
        let statusName = isOpened ? '生效中' : '已禁用';
        return (
          <div>
            <badge status={isOpened ? 'processing' : 'default'} text={statusName}/>
          </div>
        );
      },
      align: 'center'
    },
    {
      title: '折扣',
      key: 'discount',
      align: 'center',
      width: 180,
      render: (h, params) => {
        let discountValue = "";
        let couponType = params.row.type;
        if(couponType === 100){
          discountValue = '$'+params.row.faceValue;
        }else if(couponType == 200){
          discountValue = (100-params.row.discountRate*100).toFixed(1)+"%";
        }
        return h('div','满 $'+params.row.threshold+' 减 '+ discountValue)
      }
    },
  ]
};

// 和网络交互相关的参数
let params = {
  selectedCouponDefines:[],
  selectedCouponIds: [],
};

export  default  {
  tParam: params,
  tStatus:status,
  tData: data,
  couponDefineTable:couponDefineTable
};

